namespace planning_lite;

public class TaskFilter
{
    public bool ShowCompleted { get; set; } = false;
    public bool ShowObsolete { get; set; } = false;
    public DateTime? DueDate { get; set; } = null;
    public int Priority { get; set; } = 50;
    public bool sortByDueDate { get; set; } = false;
    public bool sortByPriority { get; set; } = false;

    public List<TaskItem> ApplyFilter(List<TaskItem> tasks)
    {
        var filteredTasks = tasks.Where(task =>
            (ShowCompleted || !task.IsCompleted) &&
            (ShowObsolete || !task.IsObsolete) &&
            (!DueDate.HasValue || task.DueDate <= DueDate) &&
            task.Priority >= Priority).ToList();

        if (sortByDueDate)
        {
            filteredTasks = filteredTasks.OrderBy(task => task.DueDate).ToList();
        }

        if (sortByPriority)
        {
            filteredTasks = filteredTasks.OrderByDescending(task => task.Priority).ToList();
        }

        return filteredTasks;
    }
}